package cn.tedu.xctf.boot21.controller;

import cn.tedu.xctf.boot21.Mapper.UserMapper;
import cn.tedu.xctf.boot21.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    UserMapper mapper;

    @RequestMapping("/reg")
    public  String reg(User user){
        System.out.println("user =" +user);
        //通过用户输入的用户名去查询用户信息
        User us = mapper.selectByUsername(user.getUsername());
        if (us!=null){
            return "用户名已存在!";
        }
        mapper.insert(user);
        return "注册成功";
    }
@RequestMapping("/login")
public String login(User user){
        User us = mapper.selectByUsername(user.getUsername());
        if (us!=null){
            if (user.getPassword().equals(us.getPassword())){
                return "登录成功";
            }
            return "密码错误";
        }
        return "用户名不存在";
}

}
